<template>
    <Navtitle :title="title"></Navtitle>
    <van-row>
        <van-col span="6">
            <van-sidebar v-model="active">
                <van-sidebar-item v-for="item in categoriesApiData" :title="item.cat_name" />
            </van-sidebar>
        </van-col>
        
            <van-col span="18">
                <div v-for="item in categoriesApiData[active]?.children">
                    <h4>{{ item.cat_name }}</h4>
                    <van-pull-refresh v-model="loading" @refresh="onRefresh">
                    <router-link :to="{name:'goods',params:{query:item.cat_name}}">
                        <van-grid :column-num="4">
                        <van-grid-item v-for="items in item.children" :icon="items.cat_icon" :text="items.cat_name" />
                    </van-grid>
                    </router-link>
                    </van-pull-refresh>
                </div>
            </van-col>
    </van-row>
</template>

<script setup>
import { categoriesApi } from '@/api/api';
import Navtitle from '@/components/Navtitle.vue';
import { showToast } from 'vant';
import { ref } from 'vue';
const title = '分类'
let categoriesApiData = ref([])
categoriesApi().then(res => {
    categoriesApiData.value = res.data.message
})
const active = ref(0)
const loading = ref(false);
const onRefresh = () => {
    setTimeout(() => {
        showToast('刷新成功');
        loading.value = false;
    }, 1000);
};
</script>

<style lang="scss" scoped></style>